package cn.tedu.cwfw.order.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.order.pojo.dto.OrderDTO;
import cn.tedu.cwfw.order.pojo.vo.OrderVO;
import cn.tedu.cwfw.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cwfw/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //增加订单
    @RequestMapping("/addOrder")
    public JsonResult addOrder(OrderVO orderVO) {
        log.debug("增加订单：{}", orderVO);
        orderService.addOrder(orderVO);
        return JsonResult.ok();
    }

    //查询订单列表
    @RequestMapping("list")
    public JsonResult findOrder(OrderDTO orderDTO){
        log.debug("查询订单列表：{}", orderDTO);
        List<OrderVO> orderVOList = orderService.findOrder(orderDTO);
        return JsonResult.ok(orderVOList);
    }

    @RequestMapping("/findById")
    public JsonResult findOrderById(Long id){
        log.debug("根据id查看订单详情：{}",id);
        OrderVO orderVO = orderService.findOrderById(id);
        return JsonResult.ok(orderVO);
    }

    @RequestMapping("/deleteOrder")
    public JsonResult deleteOrder(Long id){
        log.debug("根据id删除订单：{}",id);
        orderService.deleteOrder(id);
        return JsonResult.ok();
    }




}
